//查询
function searchList() {
    $.ajax({
        url:root.serviceProviderManagement.listReverseOrder,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            pageNum: 1, //当前页码
            pageSize: 50,//每页显示条数
            "parentCustomerCode":$("#ascription_lsit").val(),
            "providerName":$("#providerName").val(),
            "applyNo":$("#applyNo").val(),
            "channelOrderId": $("#channelOrderId").val(),
            "orderId":$("#orderId").val(),
            "refundSource":$("#refundSource").val(),
            "orderStatus":$("#orderStatus").val(),
            "refundReason":$("#refundReason").val(),
            "applyTimeBegin":$("#applyTimeBegin").val(),
            "applyTimeEnd":$("#applyTimeEnd").val(),
            "auditTimeBegin":$("#auditTimeBegin").val(),
            "auditTimeEnd":$("#auditTimeEnd").val(),
            "receiverProvince":$("#getArea").val(),
            "receiverCity":$("#getPlace").val(),
        }),
        success: function (data) {
            couponlist(data.data, 0);
            $('.M-box3').pagination({
                pageCount: data.data.pageCount,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url:root.serviceProviderManagement.listReverseOrder,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":50,
                            "parentCustomerCode":$("#ascription_lsit").val(),
                            "providerName":$("#providerName").val(),
                            "applyNo":$("#applyNo").val(),
                            "channelOrderId": $("#channelOrderId").val(),
                            "orderId":$("#orderId").val(),
                            "refundSource":$("#refundSource").val(),
                            "orderStatus":$("#orderStatus").val(),
                            "refundReason":$("#refundReason").val(),
                            "applyTimeBegin":$("#applyTimeBegin").val(),
                            "applyTimeEnd":$("#applyTimeEnd").val(),
                            "auditTimeBegin":$("#auditTimeBegin").val(),
                            "auditTimeEnd":$("#auditTimeEnd").val(),
                            "receiverProvince":$("#getArea").val(),
                            "receiverCity":$("#getPlace").val(),
                        }),
                        success: function (result) {
                            couponlist(result.data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
var dataSource = new Array();
var table;   //table对象
dataSource = [];
function couponlist(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    if(data.data !=null && data.data != ''){
        $.each(data.data, function (i, field) {
            var rowData = new Array();
            rowData.push(field.applyNo);
            rowData.push(field.parentCustomerName);
            rowData.push(field.providerName);
            rowData.push(field.createdAt);
            rowData.push(field.refundAmount);
            rowData.push(field.refundStatus);
            rowData.push(field.orderId);
            dataSource.push(rowData);

        });
    }
    initDataTable(dataSource);
    function initDataTable(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[3]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets":3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[4]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ""
                        if (row[5] == 10) {
                            val = '待确认'
                        }else if (row[5] == 50) {
                            val = '已完成'
                        }else if (row[5] == 60) {
                            val = '已关闭'
                        }
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val='<span class="ml-10"><a onclick="jumpData(\'详情\',\'afterSales_details.html\',\''+row[0]+'\',\''+row[6]+'\')">查看详情</a></span>'
                        return val;
                    },
                    "targets":6
                }


            ]
        });
        //权限控制函数
        power()
    };
}
ascription3()
function ascription3() {
    $.ajax({
        type: "post",
        url:root.dockingplatform.allChannelConfig,
        cache: false,  //禁用缓存
        dataType: "json",
        data: {

        },
        success: function (data) {
            if(data.errorCode=="0") {
                var dataInter=data.data;
                var interText = doT.template($("#ascription_bob").text());
                $("#ascription_lsit").html(interText(dataInter));
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

/*获取收货地址*/
discountdata(123)
function discountdata (val) {
    if(val==123){
        //初始化 省
        var user_data = {
            level: '101',
            // memberId:'10258',
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="0"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#getArea").html(cer);
                }else{
                    var cer="<option value=''>请选择收货区域</option>"
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                    }
                    $("#getArea").html(cer);
                }
            }
        };
        web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#getArea').val()
        if(special==""){
            var cer="<option value=''>请选择收货位置</option>"
            $("#getPlace").html(cer);
        }else {
            var user_data = {
                level: '102',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>'
                        $("#getPlace").html(cer);
                    }else{
                        var cer="<option value=''>请选择收货位置</option>"
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getPlace").html(cer);
                    }
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }
}

//跳转
function jumpData(title,url,applyNo,id) {
    sessionStorage.setItem("applyNos",applyNo)
    sessionStorage.setItem("afterSalesdetailid",id)
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}